cmake_minimum_required(VERSION 3.0.2)
project(lio_ndt)


# 编译配置
set(CMAKE_BUILD_TYPE "Debug") 
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
set(CMAKE_CXX_STANDARD 14)

# 依赖包：保留原有ROS组件，新增必要依赖
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  pcl_ros
  geometry_msgs
  tf
  eigen_conversions
  sensor_msgs #
)
# PCL依赖
find_package(PCL REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
# 统一管理目标库变量（原有逻辑）
set(ALL_TARGET_LIBRARIES "")


# 1. 强制设置 Glog 头文件目录（固定路径，无需修改）
set(GLOG_INCLUDE_DIR "/usr/include/glog" CACHE PATH "Glog include dir" FORCE)
# 2. 强制设置 Glog 库文件路径（替换为你查到的实际路径）
set(GLOG_LIBRARY "/usr/lib/x86_64-linux-gnu/libglog.so" CACHE FILEPATH "Glog library" FORCE)

# 3. 验证路径有效性（报错提示更清晰）
if(NOT EXISTS "${GLOG_INCLUDE_DIR}/logging.h")
  message(FATAL_ERROR "Glog 头文件缺失！请检查安装：sudo apt install libgoogle-glog-dev")
endif()
if(NOT EXISTS "${GLOG_LIBRARY}")
  message(FATAL_ERROR "Glog 库文件缺失！实际路径应为：/usr/lib/x86_64-linux-gnu/libglog.so，请重新安装")
endif()

# 4. 添加头文件目录，确保编译能找到
include_directories(${GLOG_INCLUDE_DIR})



# 引入原有第三方库配置（glog、pcl、eigen、geographic等）
include(cmake/glog.cmake)
include(cmake/pcl.cmake)
include(cmake/eigen.cmake)
include(cmake/geographic.cmake)

# 头文件路径：保留原有include和catkin路径
include_directories(
  include
  ${catkin_INCLUDE_DIRS}
  #${PCL_INCLUDE_DIRS}
  #${EIGEN3_INCLUDE_DIRS}
)
include(cmake/global_defination.cmake)  # 原有全局定义

# Catkin打包配置（保留原有）
catkin_package()

# 源文件收集：自动递归收集所有cpp文件（包含新添加的method目录下的文件）
file(GLOB_RECURSE ALL_SRCS "*.cpp")
# 剔除节点源文件（src/*_node.cpp）和第三方源文件（third_party/*.cpp）
file(GLOB_RECURSE NODE_SRCS "src/*_node.cpp")
file(GLOB_RECURSE THIRD_PARTY_SRCS "third_party/*.cpp")
list(REMOVE_ITEM ALL_SRCS ${NODE_SRCS})
list(REMOVE_ITEM ALL_SRCS ${THIRD_PARTY_SRCS})

# 注意：新添加的配准算法文件（src/method/pcl_ndt.cpp等）会被ALL_SRCS自动包含，无需手动添加
# 原因：file(GLOB_RECURSE ALL_SRCS "*.cpp")会递归扫描所有子目录的cpp文件

set(METHOD_SRCS
    src/method/pcl_icp.cpp
    src/method/pcl_ndt.cpp
)
list(APPEND ALL_SRCS ${METHOD_SRCS})


add_executable(trajectory_saver_node src/trajectory_saver_node.cpp)  # 若放在子文件夹，需补全路径
target_link_libraries(trajectory_saver_node
    ${catkin_LIBRARIES}
    ${PCL_LIBRARIES}
)


add_executable(test_frame_node src/test_frame_node.cpp ${ALL_SRCS})
add_executable(front_end_node src/front_end_node.cpp ${ALL_SRCS})
target_link_libraries(test_frame_node
    ${catkin_LIBRARIES}
    ${PCL_LIBRARIES}
    ${ALL_TARGET_LIBRARIES}
    ${GLOG_LIBRARY}
)
target_link_libraries(front_end_node ${catkin_LIBRARIES} ${ALL_TARGET_LIBRARIES})

target_link_libraries(front_end_node
    ${catkin_LIBRARIES}
    ${PCL_LIBRARIES}
    ${ALL_TARGET_LIBRARIES}
    ${GLOG_LIBRARY}
)
